package com.qin.mall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qin.mall.dao.PmsProductAttributeCategoryDao;
import com.qin.mall.domain.PmsProductAttributeCategory;
import com.qin.mall.dto.PmsProductAttributeCategoryItem;
import com.qin.mall.mapper.PmsProductAttributeCategoryMapper;
import com.qin.mall.service.PmsProductAttributeCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 覃剑
* @description 针对表【pms_product_attribute_category(产品属性分类表)】的数据库操作Service实现
* @createDate 2022-11-06 20:59:30
*/
@Service
public class PmsProductAttributeCategoryServiceImpl extends ServiceImpl<PmsProductAttributeCategoryMapper, PmsProductAttributeCategory>
    implements PmsProductAttributeCategoryService {
    
    @Autowired 
    private PmsProductAttributeCategoryMapper productAttributeCategoryMapper;
    
    @Autowired 
    private PmsProductAttributeCategoryDao productAttributeCategoryDao;
    
    //TODO 创建属性分类
    @Override
    public int create(String name) {
        PmsProductAttributeCategory attributeCategory = new PmsProductAttributeCategory();
        attributeCategory.setName(name);
        int insert = productAttributeCategoryMapper.insert(attributeCategory);
        return insert;
    }
    
    //TODO 修改属性分类
    @Override
    public int update(Long id, String name) {
        QueryWrapper<PmsProductAttributeCategory> wrapper = new QueryWrapper<>();
        wrapper.eq("id",id);
        PmsProductAttributeCategory attributeCategory = new PmsProductAttributeCategory();
        attributeCategory.setName(name);
        int update = productAttributeCategoryMapper.update(attributeCategory, wrapper);
        return update;
    }


    //TODO 删除属性分类
    @Override
    public int delete(Long id) {
        int delete = productAttributeCategoryMapper.deleteById(id);
        return delete;
    }

    //TODO 通过id获取属性分类详情
    @Override
    public PmsProductAttributeCategory getItem(Long id) {
        PmsProductAttributeCategory select = productAttributeCategoryMapper.selectById(id);
        return select;
    }

    //TODO 分页查询属性分类
    //pageNum 当前页 ，pageSize 每页显示的个数
    @Override
    public Page<PmsProductAttributeCategory> getList(Integer pageNum,Integer pageSize) {
        Page<PmsProductAttributeCategory> page = new Page<>(pageNum, pageSize);
        Page<PmsProductAttributeCategory> pages = productAttributeCategoryMapper.selectPage(page, null);
        return pages;
    }

    //TODO 获取包含属性的属性分类、分类属性一起查出来
    @Override
    public List<PmsProductAttributeCategoryItem> getListWithAttr() {
        List<PmsProductAttributeCategoryItem> list = productAttributeCategoryDao.getListWithAttr();
        return list;
    }
}




